package Demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: homechen
 * Date: 2024-03-23
 * Time: 21:52
 */
public class TestMain {
    public static void main(String[] args) {
        Integer a = 10;
        Integer b = 10;
        Integer c = 128; // 超出缓存范围，创建新对象
        Integer d = 128;
        System.out.println(a == b);
        System.out.println(c == d);
    }

    public static void main3(String[] args) {
        String str1 = "hello"; // 字符串常量池中创建对象
        String str2 = new String("hello"); // 在堆上创建 hello 对象
        String str3 = str2.intern(); // 将 str2 引用的字符串加入到常量池中
        System.out.println(str1 == str2); // false
        System.out.println(str1 == str3); // true
        System.out.println(str2 == str3); // false

        String str4 = "hello"; // 直接从字符串常量池中获取
        System.out.println(str1 == str4); // true
    }

    public static void main1(String[] args) {
        String str1 = "tc ";
        String str2 = "hello";
        String str3 = str1 + str2; // String 是不可变对象，通过 转化为 StringBuilder 来实现
        // (new StringBuilder()).append(str1).append(str2).toString();
        System.out.println(str3);

        StringBuilder stringBuilder = new StringBuilder();
        StringBuffer stringBuffer = new StringBuffer();
    }
}
